<?php

// init
include __DIR__.'/../bootstrap.php';
include FRAME_DIR.'/http/php_fpm/application.php';

view_path(ROOT_DIR.'/view/');

set_error_handler('http_err_action', E_ALL);
set_exception_handler('http_ex_action');
register_shutdown_function('http_fatel_err_action');

if_has_exception(function ($ex) {
    return json([
        'error_code' => -1,
        'error_message' => $ex->getMessage(),
        'data' => [],
    ]);
});

if_verify(function ($action, $args) {

    $data = call_user_func_array($action, $args);

    header('Content-type: text/html');

    return $data;
});

// init interceptor
include INTERCEPTOR_DIR.'/portal.php';

// init 404 handler
if_not_found(function () {
    return 404;
});

// init controller
include CONTROLLER_DIR.'/index.php';

// fix
not_found();
